package com.example.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapper.UserMapper;
import com.example.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService extends ServiceImpl<UserMapper, User> {

     @Autowired
     UserMapper userMapper;
    public void register(User user){
        this.baseMapper.insert(user);
    }

    public boolean isExist(String name){
        QueryWrapper<User> userWrapper = new QueryWrapper<>();
        List<User>userList = baseMapper.selectList(userWrapper);
        userWrapper.eq("name",name);
        int count = Math.toIntExact(userMapper.selectCount(userWrapper));
        return count > 0;
    }

    public com.example.model.User get(String username, String password){
        return this.userMapper.get(username,password);
    }
}
